package com.chis.child;

import com.chis.jm.bean.ResultStrBean;
import com.chis.jm.bean.solr.ChilIndexClientBean;
import com.chis.jm.bean.timer.ChilStateBean;
import com.chis.jm.pojo.Child;
import com.chis.jm.pojo.ChildTrans;
import com.chis.jm.pojo.TdDisease;
import com.chis.jm.pojo.TdIstabu;
import com.chis.jm.pojo.TdRefuseinoc;
import com.chis.jm.pojo.TdSpremind;

import hprose.client.HproseHttpClient;
import org.apache.commons.lang.ObjectUtils;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;


public class CreateChildTest {
    public static void main(String[] args) throws Exception {
        CreateChildTest t = new CreateChildTest();
        HproseHttpClient client = new HproseHttpClient();
        client.useService("http://10.88.88.107:8080/JmYfjzService/managerChildCard");
        client.setHeader("jmversion", "1.1");
//        //根据免疫卡号查询儿童

//        t.findChildByCardno(client);

        //3.1儿童建卡接口（市平台//320584080120170001
        t.addChildCard(client);

        //   3.2更新本地儿童基本信息接口（市平台）
//       t.updateChildInfo(client);

//      //3.6删除儿童档案接口
// （市平台）
//        t.delChildCard(client);

//      //3.8儿童发卡接口（市平台）
//        t.upChildCard(client);

//      //3.16更新禁忌症表
//		t.updateIstabu(client);

//      //3.17删除禁忌症表

//      //3.10更新不接种疫苗表
//		t.updateRefuseInoc(client);

      //3.11删除不接种疫苗表

//      //3.12更新特殊提醒内容表
//		t.updateSpremind(client);
//      //3.13删除特殊提醒内容表

//      //3.14更新疾病史表
//		t.updateDisease(client);
//      //3.15删除疾病史表

        //3.18 儿童会员标记回传接口
//        t.updateChildReg(client);
    }

    //根据免疫号查询儿童
    public void findChildByCardno(HproseHttpClient client) throws Exception {
        Long unitCode = 3202060302L;            //单位编码
        String unitLoginPwd = "32020606022019032212";//单位登录密码


        String chilCardno = "1111111111003";//免疫卡号
        try {
            ResultStrBean r = (ResultStrBean) client.invoke("findChildByCardno", new Object[]{unitCode, unitLoginPwd, chilCardno});
            System.out.println("返回代号:" + r.getTypes());
            System.out.println("返回提示内容:" + r.getMsg());
            System.out.println("value:" + r.getValue());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 3.1儿童建卡接口
     *
     * @param client
     * @throws Exception
     */
    public void addChildCard(HproseHttpClient client) throws Exception {
//    	Long unitCode = 3202060401L;			//单位编码
//		String unitLoginPwd = "32058505022017090519";		//单位登录密码
//		Long userNo = 3205850502001L;

//        Long unitCode = 3202050501l;
//        String unitLoginPwd = "32020505012019030514";
//        Long userNo = 3205850401002l;

//        Long unitCode =3202112101L;
//        String unitLoginPwd = "32021121012019030809";
//        Long userNo = 3202112101001l;
        Long unitCode =3202060302L;
        String unitLoginPwd = "32020603022019031314";
        Long userNo = 3202060302001l;
//        Long unitCode =3202060602L;
//        String unitLoginPwd = "32020606022019032212";
//        Long userNo = 3202112101001l;

        Child c = new Child();
        c.setCreateDate(new Date());
        c.setChilName("王列军1");
        c.setChilSex("1");
        c.setCreateDate(new Date());
//        c.setChilNo("32058420170701806X");
        c.setChilBirthday(new Date("2016/01/05"));
        c.setChilBirthtime("07:01");
        c.setChilHereCode(1001);
        c.setChilHabiCode(32020603);
        c.setChilHabiaddress("北京市景山公园104");
        c.setChilAddress("北京市景山公园104");
        c.setChilAddressdistrict("北京市颐和园");
        c.setChilResiCode(1);
        c.setChilAccountCode(1001);
        c.setChilArtimove(0);       //是否人工迁出
        c.setChilRegionCode(Long.parseLong(unitCode.toString() + "001"));// 区域划分编码
        c.setChilTel("05108754871");
        c.setChilMobile("15161514561");
        c.setChilAparetel("13479903690");
        c.setChilHospCode(unitCode);
        c.setChilBirthno("P121291");        //出生证号
        c.setChilFatherno("320501198702018614");
        c.setChilFather("郭敬明");
        c.setChilMotherno("320501198712012849");
        c.setChilMother("");
        c.setChilOthguard("其他监护人");
        c.setChilCreatesite(unitCode);      //建档单位
        c.setChilCreatedate(new Date());
        c.setChilCreateman(userNo.toString());
        c.setChilLeavedate(new Date("2018/01/01"));
        c.setChilCurdepartment(unitCode);// 现管理单位单位
        c.setChilIfkp(2);           //卡疤 0：无；1：有； 2：未查
        c.setChilJkdacode("JKDA01010126");
        c.setChilFyzdcode("FYZD01010126");
        c.setChilCreatemanName("刘江明");
        c.setChilCreatesiteName("陆渡社区卫生服务中心");
        c.setChilCurdepartmentName("陆渡社区卫生服务中心");
        c.setChilCreatemanNo("35032219891002621X");
        c.setChilCardno("3205850401001");
//        c.setChilCardunitcode(unitCode);
//        c.setChilCarddate(new Date());

        c.setChilRemark("rmk");

        try {
            ResultStrBean r = (ResultStrBean) client.invoke("addChildCard", new Object[]{unitCode, unitLoginPwd, c, userNo});
            System.out.println("返回代号:" + r.getTypes());
            System.out.println("返回提示内容:" + r.getMsg());
            System.out.println("value:" + r.getValue());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 3.2修改儿童基本信息接口（市平台）
     *
     * @param client
     * @throws Exception
     */
    public void updateChildInfo(HproseHttpClient client) throws Exception {
        Long unitCode = 3202060401L;            //单位编码
        String unitLoginPwd = "32020604012018101714";        //单位登录密码
        Long userNo = 3202060401001L;

        ChildTrans child = new ChildTrans();
        child.setChildCode(320206040120180023L);
        child.setChilName("朱由检1");
        child.setChilSex("1");
        child.setChilNo("32050120140301516X");
        child.setChilBirTime("10");
        child.setChilIfkp(2);
        child.setChilBirthno("Pa123321");
        child.setChilMother("杨");
        child.setChilMotherno("11010119860912880X");
        child.setChilFatherno("");
        child.setChilMobile("15161514561");
        child.setChilAparetel("051412472");
        child.setChilTel("13479903690");
        child. setChilFather("郭");
        child.setCreateDate(new Date());        //建档日期

        try {
            ResultStrBean r = (ResultStrBean) client.invoke("updateChildInfo", new Object[]{unitCode, unitLoginPwd, child, userNo});
            System.out.println("返回代号:" + r.getTypes());
            System.out.println("返回提示内容:" + r.getMsg());
            System.out.println("value:" + r.getValue());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 3.6删除儿童接口（市平台）
     *
     * @param client
     * @throws Exception
     */
    public void delChildCard(HproseHttpClient client) throws Exception {
        Long unitCode = 3202060401L;            //单位编码
        String unitLoginPwd = "32020604012018101714";        //单位登录密码
        Long userNo = 3202060401008L;

        Long ChilCode = 320206040120160780L;

        try {
            ResultStrBean r = (ResultStrBean) client.invoke("delChildCard", new Object[]{unitCode, unitLoginPwd, ChilCode, userNo});
            System.out.println("返回代号:" + r.getTypes());
            System.out.println("返回提示内容:" + r.getMsg());
            System.out.println("value:" + r.getValue());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 4.5根据条件调用省级异地儿童信息接口（市平台）
     *
     * @param client
     * @throws Exception
     */
    public void findChildByProSolr(HproseHttpClient client) throws Exception {
        //葑门街道社区
        Long unitCode = 3206110401L;            //单位编码
        String unitLoginPwd = "32061104012016101409";        //单位登录密码

        ChilIndexClientBean child = new ChilIndexClientBean();
        child.setChilbirthdayStart("2011-05-19T00:00:00Z");
        child.setChilbirthdayEnd("2011-05-19T23:59:59Z");
        child.setChilname("方雨萱");

        try {
            ResultStrBean r = (ResultStrBean) client.invoke("findChildByProSolr", new Object[]{unitCode, unitLoginPwd, child});
            System.out.println("返回代号:" + r.getTypes());
            System.out.println("返回提示内容:" + r.getMsg());
            System.out.println("value:" + r.getValue());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //3.8儿童发卡接口（市平台）
    private void upChildCard(HproseHttpClient client) {
        try {
            Long unitCode = 3205850502L;            //单位编码
            String unitLoginPwd = "32058505022017090519";        //单位登录密码
            Long userNo = 3205850502001L;

            String cardNo = "3205850502005";//免疫卡号

            Long chilCode = 320585050220170022l;//儿童编码

            ResultStrBean r = (ResultStrBean) client.invoke("upChildCard", new Object[]{unitCode, unitLoginPwd, cardNo, chilCode, userNo});

            System.out.println("返回代号:" + r.getTypes());
            System.out.println("返回提示内容:" + r.getMsg());
            System.out.println("json:" + r.getValue());

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // 不接种疫苗
    private void updateRefuseInoc(HproseHttpClient client) {
        try {
//            Long unitCode = 3205850502L;			//单位编码
//            String unitLoginPwd = "32058505022017090519";		//单位登录密码
//            Long userNo = 3205850502001L;

//            Long unitCode = 3205850401l;
//            String unitLoginPwd = "32058504012017092211";
//            Long userNo = 3205850401002l;

            long unitCode = 3202060401l;
            //登录单位密码
            String unitLoginPwd = "32020604012018101714";
            long userNo = 3202060401008l;

            Long chilCode = 320206040120170677l;

            List<TdRefuseinoc> refuseinocList = new LinkedList<TdRefuseinoc>();
            TdRefuseinoc c = new TdRefuseinoc();

            c.setBactCode("010101");
            c.setChilCode(chilCode);
            c.setCreateDate(new Date());
            c.setCreateManCode(userNo);
            c.setCreateUnitCode(unitCode);
            c.setGuid("6dc687db-5ece-40a0-9c19-cd8cf754");
            c.setRefReason(0);
            c.setRmk("wei0");
            c.setRefDate(new Date());
            c.setModifyDate(new Date());
            c.setModifyManCode(userNo);

            refuseinocList.add(c);

//			TdRefuseinoc c1 = new TdRefuseinoc();
//			c1.setBactCode("020201");
//			c1.setChilCode(chilCode);
//			c1.setCreateDate(new Date());
//			c1.setCreateManCode(userNo);
//			c1.setCreateUnitCode(unitCode);
//			c1.setGuid(UUID.randomUUID().toString());
//			c1.setModifyDate(new Date());
//			c1.setModifyManCode(userNo);
//			
//			refuseinocList.add(c1);

            ResultStrBean r = (ResultStrBean) client.invoke("updateRefuseInoc", new Object[]{unitCode, unitLoginPwd, refuseinocList, chilCode, userNo});
            System.out.println("各类错误代码:" + r.getTypes());
            System.out.println("各类错误内容:" + r.getMsg());
            System.out.println("value:" + r.getValue());

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // 特殊提醒
    private void updateSpremind(HproseHttpClient client) {
        try {
            Long unitCode = 3205840801L;            //单位编码
            String unitLoginPwd = "32058408012017070716";        //单位登录密码
            Long userNo = 3205840801001L;

            Long chilCode = 320584080120170006l;// 儿童编码

            TdSpremind spremind = new TdSpremind();
            spremind.setChilCode(chilCode);
            spremind.setCreateDate(new Date());
            spremind.setCreateManCode(userNo);
            spremind.setCreateUnitCode(unitCode);
            spremind.setModifyDate(new Date());
            spremind.setModifyManCode(userNo);
            spremind.setRemind("不能吃硬的食物，如冰糖");
            spremind.setGuid(UUID.randomUUID().toString());

            ResultStrBean r = (ResultStrBean) client.invoke("updateSpremind", new Object[]{unitCode, unitLoginPwd, spremind, chilCode, userNo});
            System.out.println("各类错误代码:" + r.getTypes());
            System.out.println("各类错误内容:" + r.getMsg());
            System.out.println("value:" + r.getValue());

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // 疾病史
    private void updateDisease(HproseHttpClient client) {
        try {
            Long unitCode = 3205840801L;            //单位编码
            String unitLoginPwd = "32058408012017070716";        //单位登录密码
            Long userNo = 3205840801001L;

            Long chilCode = 320281130220170124l;// 儿童编码

            TdDisease disease = new TdDisease();
            disease.setChilCode(chilCode);
            disease.setCreateDate(new Date());
            disease.setCreateManCode(userNo);
            disease.setCreateUnitCode(unitCode);
            disease.setModifyDate(new Date());
            disease.setModifyManCode(userNo);
            disease.setGuid(UUID.randomUUID().toString());
            disease.setDisCode("1002");
            ResultStrBean r = (ResultStrBean) client.invoke("updateDisease", new Object[]{unitCode, unitLoginPwd, disease, chilCode, userNo});
            System.out.println("各类错误代码:" + r.getTypes());
            System.out.println("各类错误内容:" + r.getMsg());
            System.out.println("value:" + r.getValue());

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // 禁忌症
    private void updateIstabu(HproseHttpClient client) {
        try {
//            Long unitCode = 3205850502L;			//单位编码
//            String unitLoginPwd = "32058505022017090519";		//单位登录密码
//            Long userNo = 3205850502001L;

            long unitCode = 3202060401l;
            //登录单位密码
            String unitLoginPwd = "32020604012018101714";
            long userNo = 3202060401008l;

            Long chilCode = 320206040120170677L;

            List<TdIstabu> istabuList = new LinkedList<TdIstabu>();
            TdIstabu c = new TdIstabu();
            c.setBactCode("020201");
            c.setChilCode(chilCode);
            c.setIstaReasonCode("1099");
            c.setIstaStartdate(new Date());
            c.setStopDate(new Date("2020/02/28"));
            c.setIfReveal(1);
            c.setRemindDate(new Date());
            c.setRmk("禁忌原因9999");
            c.setInocDelmark(0);
            c.setCreateDate(new Date(unitCode));
            c.setCreateManCode(userNo);
            c.setCreateUnitCode(unitCode);
            c.setGuid("20a762f5-581a-4bca-b1c9-c95a442706F2");
            c.setModifyDate(new Date());
            c.setModifyManCode(userNo);
            istabuList.add(c);

            ResultStrBean r = (ResultStrBean) client.invoke("updateIstabu", new Object[]{unitCode, unitLoginPwd, istabuList, chilCode, userNo});
            System.out.println("各类错误代码:" + r.getTypes());
            System.out.println("各类错误内容:" + r.getMsg());
            System.out.println("value:" + r.getValue());

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //3.18 儿童会员标记回传接口
    public void updateChildReg(HproseHttpClient client) throws Exception {
        Long unitCode = 3206020201L;//单位编码
        String unitLoginPwd = "32060202012017102411";//单位登录密码

        List<ChilStateBean> chilList = new ArrayList<>();

        ChilStateBean chilReg = new ChilStateBean();
        chilReg.setChildCode(320602020120140492l);
        chilReg.setIfApp(1);
        chilReg.setAppTime(new Date());
        chilReg.setIfWx(0);

        chilList.add(chilReg);

        try {
            ResultStrBean r = (ResultStrBean) client.invoke("updateChildReg", new Object[]{unitCode, unitLoginPwd, chilList});
            System.out.println("各类错误代码:" + r.getTypes());
            System.out.println("各类错误内容:" + r.getMsg());
            System.out.println("value:" + r.getValue());

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
